﻿using System.Data;

namespace Login.ADL
{
   public  class tb_shiyanclass
    {
       /// <summary>
        /// 所有实验班级表格提取
       /// </summary>
        /// <returns></returns>
        #region
        public static DataSet getData()
       {
           //构造搜索班级名称的sql语句
           string sql = "select ClassId,ClassName from tb_Class";
           //搜索班级名称
           DataSet ds = Helpsql.getdata(sql);
            //返回表
           return ds;
       }
        #endregion


       /// <summary>
       /// 班级实验数
       /// </summary>
       /// <param name="banJiName">班级名称</param>
       /// <returns></returns>
       #region
       public int getExpermentShu(string banJiName)
       {
           //班级ID提取
           string id = tb_shangkeClass.getClassId(banJiName);
           //构造班级实验数的sql语句
           string sql = "select count(*) from tb_Class_Exp_Details where ClassId='{0}'";
           sql = string.Format(sql, id);
           //提取班级实验数
           int n = Helpsql.getshu(sql);
           return n;
       }
        #endregion

       /// <summary>
       /// 班级所有实验数
       /// </summary>
       /// <param name="banJiName">班级名称</param>
       /// <returns></returns>
       #region
       public string[] getExpermentIdZu(string banJiName)
       {
           //提取班级实验数
           int n = getExpermentShu(banJiName);
           //提取当前班级ID
           string id = tb_shangkeClass.getClassId(banJiName);
           //构造提取班级所有实验ID
           string sql = "select * from tb_Class_Exp_Details where ClassId='{0}'";
           sql = string.Format(sql,id);
           //提取班级所有实验ID
           string[] str = Helpsql.getzu(sql, n);
           return str;
       }
       #endregion

       /// <summary>
       /// 删除实验相关信息
       /// </summary>
       /// <param name="banJiID">班级的ID</param>
       #region
       public static void delete(string banJiID)
       {
           //创建删除班级原有的实验的SQL语句
           string sql = "delete from tb_Class_Exp_Details where ClassId='{0}'";
           sql = string.Format(sql,banJiID);
           //删除班级原有的实验
           Helpsql.getxiu(sql);
       }
        #endregion

       /// <summary>
       /// 班级实验数添加
       /// </summary>
       /// <param name="banjiID">班级ID</param>
       /// <param name="shiyanID">实验ID</param>
       #region
       public static void ExpermentAdd(string banJiID, string shiYanID)
       {
           //构造添加班级实验的sql语句
           string sql = "insert into tb_Class_Exp_Details(ClassId,ExperimentId)values('{0}','{1}')";
           sql = string.Format(sql,banJiID,shiYanID);
           //添加班级实验
           Helpsql.getxiu(sql);
       }
       #endregion

       /// <summary>
       /// 搜索实验是否存在
       /// </summary>
       /// <param name="ExperimentID">实验ID</param>
       /// <returns></returns>
       #region
       public static string ExperimentNameJudge(int ExperimentID)
       {
           //构造搜索实验名的sql语句
           string sql = "select ExperimentNo from tb_Experiment where ExperimentId='{0}'";
           sql = string.Format(sql, ExperimentID);
           //搜索实验名
           string shiyanming = Helpsql.getgeti(sql);
           return shiyanming;
       }
        #endregion
    }
}
